﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SDL
{
	public static class IntExtension
	{
		/*
		 * Console.WriteLine(3.Weeks().Ago);
         * Console.WriteLine(5.Years().FromNow);
         * Console.WriteLine(19.Days().From(new DateTime(2007,1,1)));
		 */
		public static TimeSelector Weeks(this int i)
		{
			return (new WeekSelector { ReferenceValue = i });
		}

		public static TimeSelector Days(this int i)
		{
			return (new DaysSelector { ReferenceValue = i });
		}

		public static TimeSelector Years(this int i)
		{
			return (new YearsSelector { ReferenceValue = i });
		}

		/*
		 * 2.IterateTo(5, i => Console.WriteLine(i));
		 * (-10).IterateTo(-12, i => Console.WriteLine(i));
		 * 2.IterateTo(20, c => c + 2, i => Console.WriteLine(i));
		 */
		public static void IterateTo(this int start, int end, Func<int, int> modify, Action<int> action)
		{
			int prefix = end < start ? -1 : 1;

			for (int i = prefix * start; i <= prefix * end; i = modify(i))
			{
				action(prefix * i);
			}
		}

		public static void IterateTo(this int start, int end, Action<int> action)
		{
			IterateTo(start, end, i => i + 1, action);
		}
	}
}
